import { defineStore } from 'pinia'

export const useLayoutStore = defineStore('layout', {
	state: () => {
		return {
			w: 6, // 默认宽度
			h: 4, // 默认高度
			rowHeight: 30, // 默认行高
			layoutType: 'PC', // 默认布局类型
			colNum: {
				// 默认列数
				lg: 24,
				sm: 24,
				xxs: 12
			},
			margin: [10, 10] // 默认间距
		}
	},
	getters: {
		getRowHeight: (state) => {
			return state.rowHeight
		},
		getColNum: (state) => {
			return state.colNum
		},
		getMargin: (state) => {
			return state.margin
		},
		getState: (state) => {
			return {
				rowHeight: state.rowHeight,
				colNum: state.colNum,
				margin: state.margin,
				layoutType: state.layoutType,
				w: state.w,
				h: state.h
			}
		}
	},
	actions: {
		setRowHeight(rowHeight: number) {
			this.rowHeight = rowHeight
		},
		setColNum(colNum: number) {
			this.colNum = colNum
		},
		setMargin(margin: number[]) {
			this.margin = margin
		},
		setState(data: any) {
			this.rowHeight = data.rowHeight || this.rowHeight
			this.colNum = data.colNum || this.colNum
			this.margin = data.margin || this.margin
			this.layoutType = data.layoutType || this.layoutType
			this.w = data.w || this.w
			this.h = data.h || this.h
		},
		changeLayout(type: string) {
			this.layoutType = type
		}
	}
})
